/*#include<stdio.h>
int findluckynumber(int arr[],int n)
{
	int count[10]={0};
	for(int i=0;i<=n-1;i++)
	{
		count[arr[i]]++;
	}
	int luckynumber=-1;
	for(int i=9;i>=0;i--)
	{
		if(count[i]==i)
		{
			luckynumber=i;
			break;
		}
	}
	return luckynumber;
}
int main()
{
	int n,i;
	scanf("%d",&n);
	int arr[10];
	for(i=0;i<=n-1;i++)
	{
		scanf("%d",&arr[i]);
	}
	int result=findluckynumber(arr,n);
	printf("%d",result);
	return 0;
	
} */
/*#include <stdio.h>

int findLuckyNumber(int arr[], int n) {
    int count[10] = {0};
    for (int i = 0; i < n; i++) {
        count[arr[i]]++;
    }
    int luckyNumber = -1;
    for (int i = 9; i >= 0; i--) {
        if (count[i] == i) {
            luckyNumber = i;
            break;
        }
    }
    return luckyNumber;
}

int main() {
    int n;
    scanf("%d", &n);
    int arr[10];
    for (int i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
    }
    int result = findLuckyNumber(arr, n);
    printf("%d", result);
    return 0;
}*/
#include<stdio.h>
int main()
{
	int i,n,j;
	scanf("%d",&n);
	int arr[10],count[10]={0};
	for(i=0;i<=n-1;i++)
	{
		scanf("%d",&arr[i]);
	}
	for(i=0;i<=n-1;i++)
	{
		count[arr[i]]++;
	}
	int luckynumber=-1;
	for(i=9;i>0;i--)
	{
		
		if(count[i]==i)
		{
			luckynumber=i;
			break;
		}
	}
	printf("%d",luckynumber);
	return 0;
}

